﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using WebUS;
using WebDS;
using IP.Core.IPCommon;
using WebDS.CDBNames;
using System.Data;

public partial class ChucNang_test : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (m_lbl_state.Text == "0")
        {
            load_data_2_lbl_bai();
            load_data_2_m_p_noi_dung_cau();
            m_lbl_state.Text = "1";
        }
        if (!IsPostBack)
        {
            //table_case_study.Rows[0].Visible = false;
            //table_case_study.Rows[1].Visible = false;
            
            m_hdf_index.Value = "0";
            m_lbl_stt.Text = "1";
            load_data_2_lbl_bai();
            m_hdf_index_items.Value = "0";
            load_data_2_m_p_noi_dung_cau();
            m_hdf_index_items.Value = "0";
            m_hdf_trang_thai.Value = "0";
            m_hdf_str.Value = "";
        }

        if (m_hdf_index_items.Value == "0")
        {
            m_hdf_str.Value = "";
        }
    }
    

    private void load_data_2_lbl_bai()
    {
        decimal v_dc_index = new decimal();
        v_dc_index = CIPConvert.ToDecimal(m_hdf_index.Value);
        US_DM_BAI_TEST v_us_dm_bai_test = new US_DM_BAI_TEST();
        DS_DM_BAI_TEST v_ds_dm_bai_test = new DS_DM_BAI_TEST();
        v_us_dm_bai_test.FillDatasetAndSortBySTT(v_ds_dm_bai_test);
        m_hdf_index_2.Value = CIPConvert.ToStr(v_ds_dm_bai_test.DM_BAI_TEST.Count);
        if ((v_dc_index >= 0) && (v_dc_index < v_ds_dm_bai_test.DM_BAI_TEST.Count))
        {
            DataTable dt = v_ds_dm_bai_test.Tables["DM_BAI_TEST"];
            DataRow dr = dt.Rows[(int)CIPConvert.ToDecimal(m_hdf_index.Value)];
            m_lbl_bai.Text = "Bài test : " + dr["BAI_TEST"].ToString();
            US_DM_CAU v_us_dm_cau = new US_DM_CAU();
            DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
            m_hdf_id_bai_test.Value = dr["ID"].ToString();
            v_us_dm_cau.FillDatasetByIdAndSort(CIPConvert.ToDecimal(m_hdf_id_bai_test.Value), v_ds_dm_cau);
            m_lbl_tong_so_cau.Text = v_ds_dm_cau.DM_CAU.Count.ToString();
            if (m_lbl_tong_so_cau.Text == "0")
            {
                m_lbl_stt.Text = "0";
            }
            else
            {
                m_lbl_stt.Text = "1";
            }
        }
        else
        {
            m_lbl_bai.Text = "";
        }
    }

    protected void m_cmd_next_Click(object sender, ImageClickEventArgs e)
    {
        m_hdf_trang_thai.Value = "0";
        decimal index = CIPConvert.ToDecimal(m_hdf_index.Value);
        decimal count = CIPConvert.ToDecimal(m_hdf_index_2.Value);
        if ((index != 0) && (count != 0))
        {
            index = (index + 1) % count;
        }
        else
        {
            index = 1;
        }
        m_hdf_index.Value = CIPConvert.ToStr(index);
        load_data_2_lbl_bai();
        m_hdf_index_items.Value = "0";
        load_data_2_m_p_noi_dung_cau();
    }
    
    protected void m_cmd_prev_Click(object sender, ImageClickEventArgs e)
    {
        m_hdf_trang_thai.Value = "0";
        decimal index = CIPConvert.ToDecimal(m_hdf_index.Value);
        decimal count = CIPConvert.ToDecimal(m_hdf_index_2.Value);
        if ((index != 0) && (count != 0))
        {
            index = (index - 1) % count;
        }
        else
        {
            index = count - 1;
        }

        m_hdf_index.Value = CIPConvert.ToStr(index);
        load_data_2_lbl_bai();
        m_hdf_index_items.Value = "0";
        load_data_2_m_p_noi_dung_cau();
    }

    protected void m_cmd_next_cau_Click(object sender, ImageClickEventArgs e)
    {
        m_hdf_trang_thai.Value = "0";
        if (m_lbl_tong_so_cau.Text != "0")
        {
            decimal v_dc_stt = CIPConvert.ToDecimal(m_lbl_stt.Text);
            decimal v_dc_tong_so_cau = CIPConvert.ToDecimal(m_lbl_tong_so_cau.Text);
            v_dc_stt = v_dc_stt % v_dc_tong_so_cau + 1;
            m_lbl_stt.Text = CIPConvert.ToStr(v_dc_stt);
            m_hdf_index_items.Value = "0";
        }
        load_data_2_m_p_noi_dung_cau();
    }

    protected void m_cmd_prev_cau_Click(object sender, ImageClickEventArgs e)
    {
        m_hdf_trang_thai.Value = "0";
        if (m_lbl_tong_so_cau.Text != "0")
        {
            decimal v_dc_stt = CIPConvert.ToDecimal(m_lbl_stt.Text);
            decimal v_dc_tong_so_cau = CIPConvert.ToDecimal(m_lbl_tong_so_cau.Text);
            v_dc_stt = (v_dc_stt - 1 + v_dc_tong_so_cau - 1) % v_dc_tong_so_cau + 1;
            m_lbl_stt.Text = CIPConvert.ToStr(v_dc_stt);
            m_hdf_index_items.Value = "0";
        }
        load_data_2_m_p_noi_dung_cau();
    }

    private void load_data_2_m_p_noi_dung_cau() 
    {
        if (m_lbl_tong_so_cau.Text == "0")
        {
            m_p_noi_dung_cau.InnerText = "";
        }
        else
        {
            if (m_hdf_index_items.Value == "0")
            {
                US_DM_CAU v_us_dm_cau = new US_DM_CAU();
                DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
                v_us_dm_cau.FillDatasetByIdAndSort(CIPConvert.ToDecimal(m_hdf_id_bai_test.Value), v_ds_dm_cau);
                DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
                DataRow dr = dt.Rows[(int)CIPConvert.ToDecimal(m_lbl_stt.Text)-1];
                m_p_noi_dung_cau.InnerHtml = dr["NOI_DUNG_CAU"].ToString();
                m_hdf_id_cau.Value = dr["ID"].ToString();
            }
            else
            {
                US_DM_ITEMS v_us_dm_item = new US_DM_ITEMS();
                DS_DM_ITEMS v_ds_dm_item = new DS_DM_ITEMS();
                v_us_dm_item.FillDatasetByIdAndSort(CIPConvert.ToDecimal(m_hdf_id_cau.Value), v_ds_dm_item);
                m_hdf_tong_so_items.Value = v_ds_dm_item.DM_ITEMS.Count.ToString();
                DataTable dt = v_ds_dm_item.Tables["DM_ITEMS"];
                DataRow dr = dt.Rows[(int)CIPConvert.ToDecimal(m_hdf_index_items.Value)-1];
                m_p_noi_dung_cau.InnerHtml = dr["CAU_CHUA_ITEMS"].ToString();
            }
        }
        load_m_p_giai_thich_chung();
        load_data_2_table_noi_dung();
    }

    protected void m_cmd_prev_item_Click(object sender, ImageClickEventArgs e)
    {
        if (m_hdf_index_items.Value == "0")
        {
            m_hdf_trang_thai.Value = "1";
            m_hdf_index_items.Value = m_hdf_tong_so_items.Value;
        }
        else
        {
            m_hdf_index_items.Value = CIPConvert.ToStr(CIPConvert.ToDecimal(m_hdf_index_items.Value)-1);
        }
        load_data_2_m_p_noi_dung_cau();
    }
    
    protected void m_cmd_next_item_Click(object sender, ImageClickEventArgs e)
    {
        if (m_hdf_index_items.Value == m_hdf_tong_so_items.Value)
        {
            m_hdf_trang_thai.Value = "1";
            m_hdf_index_items.Value = "0";
        }
        else
        {
            m_hdf_index_items.Value = CIPConvert.ToStr(CIPConvert.ToDecimal(m_hdf_index_items.Value) + 1);
        }
        load_data_2_m_p_noi_dung_cau();
    }

    private void load_m_p_giai_thich_chung()
    {
        if (m_lbl_tong_so_cau.Text == "0")
        {
            m_p_giai_thich_chung.InnerText = "";
        }
        else
        {
            US_DM_CAU v_us_dm_cau = new US_DM_CAU();
            DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
            v_us_dm_cau.FillDatasetByIdAndSort(CIPConvert.ToDecimal(m_hdf_id_bai_test.Value), v_ds_dm_cau);
            DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
            DataRow dr = dt.Rows[(int)CIPConvert.ToDecimal(m_lbl_stt.Text) - 1];
            
            m_p_giai_thich_chung.InnerHtml = dr["CHU_THICH_CHUNG"].ToString();
            m_hdf_id_cau.Value = dr["ID"].ToString();
        }        
    }

    private void load_data_2_table_noi_dung()
    {        
        if (m_lbl_tong_so_cau.Text != "0")
        
            if (m_hdf_index_items.Value == "0")
            {
                table_case_study.Visible = false;
                table_htkt.Visible = false;
                //Nếu index = 1000 thì hiển thị ra nghĩa của câu
                US_DM_CAU v_us_dm_cau = new US_DM_CAU();
                DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
                v_us_dm_cau.FillDatasetByIdAndSort(CIPConvert.ToDecimal(m_hdf_id_bai_test.Value), v_ds_dm_cau);
                DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
                DataRow dr = dt.Rows[(int)CIPConvert.ToDecimal(m_lbl_stt.Text) - 1];
                if (m_hdf_trang_thai.Value == "1")
                {
                    HtmlTableRow tr = new HtmlTableRow();
                    table_dich_nghia.Rows.Add(tr);
                    HtmlTableCell td = new HtmlTableCell();
                    tr.Cells.Add(td);
                    td.InnerHtml = dr["DICH_NGHIA"].ToString();
                    td.Attributes.Add("align","center");
                }
                m_hdf_id_cau.Value = dr["ID"].ToString();
                
            }
            else
            {
                table_htkt.Visible = true;
                //Nếu index != 0 thì in ra danh sách items
                US_DM_ITEMS v_us_dm_item = new US_DM_ITEMS();
                DS_DM_ITEMS v_ds_dm_item = new DS_DM_ITEMS();
                v_us_dm_item.FillDatasetByIdAndSort(CIPConvert.ToDecimal(m_hdf_id_cau.Value), v_ds_dm_item);
                m_hdf_tong_so_items.Value = v_ds_dm_item.DM_ITEMS.Count.ToString();
                DataTable dt = v_ds_dm_item.Tables["DM_ITEMS"];
                int count = (int)CIPConvert.ToDecimal(m_hdf_index_items.Value); 
                //In ra nội dung của các items trước
                #region items_truoc
                for (int i = 0; i < count - 1; i++)
                {
                    if (i == 0)
                    {
                        m_hdf_str.Value = "";
                    }
                    if (i == count - 2)
                    {
                        DataRow dr = dt.Rows[i];
                        HtmlTableRow tr = new HtmlTableRow();
                        table_noi_dung.Rows.Add(tr);
                        HtmlTableCell td = new HtmlTableCell();
                        tr.Cells.Add(td);

                        //m_hdf_str.Value =m_hdf_str.Value +" "+ "<font style='color:red'>" + dr["NOI_DUNG"].ToString() + "</font>";
                        td.InnerHtml = dr["NOI_DUNG"].ToString();
                        td.Attributes.Add("height", "20px");
                    }
                }
                #endregion
                //In ra nội dung của item hiện tại  
                #region noi_dung
                DataRow dr1 = dt.Rows[count-1];
                HtmlTableRow tr1 = new HtmlTableRow();
                table_noi_dung.Rows.Add(tr1);
                HtmlTableCell td1 = new HtmlTableCell();
                tr1.Cells.Add(td1);
                //td1.InnerHtml =m_hdf_str.Value +" "+ "<font style='color:red'>" + dr1["NOI_DUNG"].ToString() + "</font>";
                td1.InnerHtml = dr1["NOI_DUNG"].ToString();
                #endregion
                //In ra giải thích của items hiện tại
                #region giai_thich
                HtmlTableRow tr2 = new HtmlTableRow();
                table_giai_thich_item.Rows.Add(tr2);
                HtmlTableCell td2 = new HtmlTableCell();
                tr2.Cells.Add(td2);
                td2.InnerHtml = "<b><i>Giải thích:</i></b><br>" + dr1["GIAI_THICH"].ToString();
                #endregion
                //In ra hệ thống kiến thức của items hiện tại
                #region htkt
                m_link_htkt.Text = dr1["TIEU_DE_HTKT"].ToString();
                m_link_htkt.NavigateUrl = dr1["LINK_HTKT"].ToString();
                #endregion
                //In ra case study của item hiện tại
                #region case_study

                for (int i = 0; i < 10; i++)
                {
                    LinkButton s = (LinkButton)table_case_study.FindControl("cs" + (i+1).ToString());
                    s.Text = "";
                }


                decimal v_dc_id_item = CIPConvert.ToDecimal(dr1["ID"].ToString());
                US_V_DM_CASE_STUDY v_us_v_dm_case_study = new US_V_DM_CASE_STUDY();
                DS_V_DM_CASE_STUDY v_ds_v_dm_case_study = new DS_V_DM_CASE_STUDY();
                v_us_v_dm_case_study.FillDatasetById(v_dc_id_item, v_ds_v_dm_case_study);
                if (v_ds_v_dm_case_study.V_DM_CASE_STUDY.Count == 1)
                {
                    table_case_study.Visible = true;
                    table_case_study.Rows[0].Visible = true;
                    table_case_study.Rows[1].Visible = false;
                    table_case_study.Rows[2].Visible = false;
                    DataTable dt2 = v_ds_v_dm_case_study.Tables["V_DM_CASE_STUDY"];
                    DataRow dr3 = dt2.Rows[0];
                    //table_case_study.Rows[0].Cells[0].InnerHtml = dr3["CAU_CHUA_ITEMS"].ToString();
                    cs1.Text = dr3["CAU_CHUA_ITEMS"].ToString();
                    decimal id_item_tuong_ung = CIPConvert.ToDecimal(dr3["ID_ITEMS_TUONG_UNG"].ToString());
                    
                    table_index.Rows[0].Cells[0].InnerText = CIPConvert.ToStr(get_index_bai_test(id_item_tuong_ung));
                    decimal id_bai_test = CIPConvert.ToDecimal(get_id_bai_test(id_item_tuong_ung));
                    table_index.Rows[0].Cells[1].InnerText = CIPConvert.ToStr(get_index_cau(id_item_tuong_ung, id_bai_test)+1);

                    decimal id_item = CIPConvert.ToDecimal(dr3["ID_ITEMS_TUONG_UNG"].ToString());
                    US_DM_ITEMS v_us_dm_items = new US_DM_ITEMS(id_item);
                    v_us_dm_items.FillDataset(v_ds_dm_item);
                    DataTable dt3 = v_ds_dm_item.Tables["DM_ITEMS"];
                    DataRow dr4 = dt3.Rows[0];
                    table_index.Rows[0].Cells[2].InnerText = CIPConvert.ToStr(dr4["STT"]);
                }
                else
                {
                    for (int i = 0; i < v_ds_v_dm_case_study.V_DM_CASE_STUDY.Count; i++)
                    {
                        table_case_study.Visible = true;
                        table_case_study.Rows[i].Visible = true;
                        DataTable dt2 = v_ds_v_dm_case_study.Tables["V_DM_CASE_STUDY"];
                        DataRow dr3 = dt2.Rows[i];
                        //table_case_study.Rows[i].Cells[0].InnerHtml = dr3["CAU_CHUA_ITEMS"].ToString();
                        LinkButton s = (LinkButton)table_case_study.Rows[i].Cells[0].FindControl("cs" + (i+1).ToString());
                        s.Text = dr3["CAU_CHUA_ITEMS"].ToString();
                        decimal id_item_tuong_ung = CIPConvert.ToDecimal(dr3["ID_ITEMS_TUONG_UNG"].ToString());

                        table_index.Rows[i].Cells[0].InnerText = CIPConvert.ToStr(get_index_bai_test(id_item_tuong_ung));
                        decimal id_bai_test = CIPConvert.ToDecimal(get_id_bai_test(id_item_tuong_ung));
                        table_index.Rows[i].Cells[1].InnerText = CIPConvert.ToStr(get_index_cau(id_item_tuong_ung, id_bai_test)+1);
                        decimal id_item = CIPConvert.ToDecimal(dr3["ID_ITEMS_TUONG_UNG"].ToString());
                        US_DM_ITEMS v_us_dm_items = new US_DM_ITEMS(id_item);
                        v_us_dm_items.FillDataset(v_ds_dm_item);
                        DataTable dt3 = v_ds_dm_item.Tables["DM_ITEMS"];
                        DataRow dr4 = dt3.Rows[0];
                        table_index.Rows[i].Cells[2].InnerText = CIPConvert.ToStr(dr4["STT"]);
                    }
                }
                #endregion   
            }
    }

    private decimal get_id_bai_test(decimal id_item_tuong_ung)
    {
        US_V_DM_ITEMS_CAU v_us_dm_item_cau = new US_V_DM_ITEMS_CAU();
        DS_V_DM_ITEMS_CAU v_ds_dm_item_cau = new DS_V_DM_ITEMS_CAU();

        v_us_dm_item_cau.FillDatasetByID(v_ds_dm_item_cau, id_item_tuong_ung);
        DataTable dt = v_ds_dm_item_cau.Tables["V_DM_ITEMS_CAU"];
        DataRow dr = dt.Rows[0];
        decimal id_bai_test = CIPConvert.ToDecimal(dr["ID_BAI_TEST"].ToString());
        return id_bai_test;
    }

    private decimal get_index_cau(decimal id_item_tuong_ung, decimal id_bai_test)
    {
        US_V_DM_ITEMS_CAU v_us_dm_item_cau = new US_V_DM_ITEMS_CAU();
        DS_V_DM_ITEMS_CAU v_ds_dm_item_cau = new DS_V_DM_ITEMS_CAU();
        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();

        v_us_dm_item_cau.FillDatasetByID(v_ds_dm_item_cau, id_item_tuong_ung);
        DataTable dt = v_ds_dm_item_cau.Tables["V_DM_ITEMS_CAU"];
        DataRow dr = dt.Rows[0];
        decimal id_cau = CIPConvert.ToDecimal(dr["ID_CAU"].ToString());
        decimal index = new decimal();
        v_us_dm_cau.FillDatasetByIdAndSort(id_bai_test, v_ds_dm_cau);
        DataTable dt2 = v_ds_dm_cau.Tables["DM_CAU"];
        
        for (int i = 0; i < dt2.Rows.Count; i++)
        {
            DataRow dr2 = dt2.Rows[i];
            if (dr2["ID"].ToString() == id_cau.ToString())
            {
                index = i;
                break;
            }
        }
        return index;
    }

    private decimal get_index_bai_test(decimal id_item_tuong_ung)
    {
        US_V_DM_ITEMS_CAU v_us_dm_item_cau = new US_V_DM_ITEMS_CAU();
        DS_V_DM_ITEMS_CAU v_ds_dm_item_cau = new DS_V_DM_ITEMS_CAU();
        US_DM_BAI_TEST v_us_dm_bai_test = new US_DM_BAI_TEST();
        DS_DM_BAI_TEST v_ds_dm_bai_test = new DS_DM_BAI_TEST();

        v_us_dm_item_cau.FillDatasetByID(v_ds_dm_item_cau, id_item_tuong_ung);
        DataTable dt = v_ds_dm_item_cau.Tables["V_DM_ITEMS_CAU"];
        DataRow dr = dt.Rows[0];
        decimal id_bai_test = CIPConvert.ToDecimal(dr["ID_BAI_TEST"].ToString());
        decimal index = new decimal();
        v_us_dm_bai_test.FillDataset(v_ds_dm_bai_test);
        DataTable dt2 = v_ds_dm_bai_test.Tables["DM_BAI_TEST"];
        for (int i = 0; i < dt2.Rows.Count; i++)
        {
            DataRow dr2 = dt2.Rows[i];
            if (dr2["ID"].ToString() == id_bai_test.ToString())
            {
                index = i;
                break;
            }
        }
        return index;
    }
    protected void cs1_Click(object sender, EventArgs e)
    {
        m_hdf_index.Value = table_index.Rows[0].Cells[0].InnerText;
        load_data_2_lbl_bai();
        m_lbl_stt.Text = table_index.Rows[0].Cells[1].InnerText;
        m_hdf_index_items.Value = table_index.Rows[0].Cells[2].InnerText;

        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
        v_us_dm_cau.FillDatasetBySTT(v_ds_dm_cau,CIPConvert.ToDecimal(m_lbl_stt.Text), CIPConvert.ToDecimal(m_hdf_id_bai_test.Value));
        DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
        DataRow dr = dt.Rows[0];
        m_hdf_id_cau.Value = dr["ID"].ToString();

        load_data_2_m_p_noi_dung_cau();
    }

    protected void cs2_Click(object sender, EventArgs e)
    {
        m_hdf_index.Value = table_index.Rows[1].Cells[0].InnerText;
        load_data_2_lbl_bai();
        m_lbl_stt.Text = table_index.Rows[1].Cells[1].InnerText;
        m_hdf_index_items.Value = table_index.Rows[1].Cells[2].InnerText;

        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
        v_us_dm_cau.FillDatasetBySTT(v_ds_dm_cau, CIPConvert.ToDecimal(m_lbl_stt.Text), CIPConvert.ToDecimal(m_hdf_id_bai_test.Value));
        DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
        DataRow dr = dt.Rows[0];
        m_hdf_id_cau.Value = dr["ID"].ToString();

        load_data_2_m_p_noi_dung_cau();
    }

    protected void cs3_Click(object sender, EventArgs e)
    {
        m_hdf_index.Value = table_index.Rows[2].Cells[0].InnerText;
        load_data_2_lbl_bai();
        m_lbl_stt.Text = table_index.Rows[2].Cells[1].InnerText;
        m_hdf_index_items.Value = table_index.Rows[2].Cells[2].InnerText;

        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
        v_us_dm_cau.FillDatasetBySTT(v_ds_dm_cau, CIPConvert.ToDecimal(m_lbl_stt.Text), CIPConvert.ToDecimal(m_hdf_id_bai_test.Value));
        DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
        DataRow dr = dt.Rows[0];
        m_hdf_id_cau.Value = dr["ID"].ToString();

        load_data_2_m_p_noi_dung_cau();
    }

    protected void cs4_Click(object sender, EventArgs e)
    {
        m_hdf_index.Value = table_index.Rows[3].Cells[0].InnerText;
        load_data_2_lbl_bai();
        m_lbl_stt.Text = table_index.Rows[3].Cells[1].InnerText;
        m_hdf_index_items.Value = table_index.Rows[3].Cells[2].InnerText;

        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
        v_us_dm_cau.FillDatasetBySTT(v_ds_dm_cau, CIPConvert.ToDecimal(m_lbl_stt.Text), CIPConvert.ToDecimal(m_hdf_id_bai_test.Value));
        DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
        DataRow dr = dt.Rows[0];
        m_hdf_id_cau.Value = dr["ID"].ToString();

        load_data_2_m_p_noi_dung_cau();
    }

    protected void cs5_Click(object sender, EventArgs e)
    {
        m_hdf_index.Value = table_index.Rows[4].Cells[0].InnerText;
        load_data_2_lbl_bai();
        m_lbl_stt.Text = table_index.Rows[4].Cells[1].InnerText;
        m_hdf_index_items.Value = table_index.Rows[4].Cells[2].InnerText;
        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
        v_us_dm_cau.FillDatasetBySTT(v_ds_dm_cau, CIPConvert.ToDecimal(m_lbl_stt.Text), CIPConvert.ToDecimal(m_hdf_id_bai_test.Value));
        DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
        DataRow dr = dt.Rows[0];
        m_hdf_id_cau.Value = dr["ID"].ToString();
        load_data_2_m_p_noi_dung_cau();
    }

    protected void cs6_Click(object sender, EventArgs e)
    {
        m_hdf_index.Value = table_index.Rows[5].Cells[0].InnerText;
        load_data_2_lbl_bai();
        m_lbl_stt.Text = table_index.Rows[5].Cells[1].InnerText;
        m_hdf_index_items.Value = table_index.Rows[5].Cells[2].InnerText;
        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
        v_us_dm_cau.FillDatasetBySTT(v_ds_dm_cau, CIPConvert.ToDecimal(m_lbl_stt.Text), CIPConvert.ToDecimal(m_hdf_id_bai_test.Value));
        DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
        DataRow dr = dt.Rows[0];
        m_hdf_id_cau.Value = dr["ID"].ToString();
        load_data_2_m_p_noi_dung_cau();
    }

    protected void cs7_Click(object sender, EventArgs e)
    {
        m_hdf_index.Value = table_index.Rows[6].Cells[0].InnerText;
        load_data_2_lbl_bai();
        m_lbl_stt.Text = table_index.Rows[6].Cells[1].InnerText;
        m_hdf_index_items.Value = table_index.Rows[6].Cells[2].InnerText;
        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
        v_us_dm_cau.FillDatasetBySTT(v_ds_dm_cau, CIPConvert.ToDecimal(m_lbl_stt.Text), CIPConvert.ToDecimal(m_hdf_id_bai_test.Value));
        DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
        DataRow dr = dt.Rows[0];
        m_hdf_id_cau.Value = dr["ID"].ToString();
        load_data_2_m_p_noi_dung_cau();
    }

    protected void cs8_Click(object sender, EventArgs e)
    {
        m_hdf_index.Value = table_index.Rows[7].Cells[0].InnerText;
        load_data_2_lbl_bai();
        m_lbl_stt.Text = table_index.Rows[7].Cells[1].InnerText;
        m_hdf_index_items.Value = table_index.Rows[7].Cells[2].InnerText;
        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
        v_us_dm_cau.FillDatasetBySTT(v_ds_dm_cau, CIPConvert.ToDecimal(m_lbl_stt.Text), CIPConvert.ToDecimal(m_hdf_id_bai_test.Value));
        DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
        DataRow dr = dt.Rows[0];
        m_hdf_id_cau.Value = dr["ID"].ToString();
        load_data_2_m_p_noi_dung_cau();
    }

    protected void cs9_Click(object sender, EventArgs e)
    {
        m_hdf_index.Value = table_index.Rows[8].Cells[0].InnerText;
        load_data_2_lbl_bai();
        m_lbl_stt.Text = table_index.Rows[8].Cells[1].InnerText;
        m_hdf_index_items.Value = table_index.Rows[8].Cells[2].InnerText;
        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
        v_us_dm_cau.FillDatasetBySTT(v_ds_dm_cau, CIPConvert.ToDecimal(m_lbl_stt.Text), CIPConvert.ToDecimal(m_hdf_id_bai_test.Value));
        DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
        DataRow dr = dt.Rows[0];
        m_hdf_id_cau.Value = dr["ID"].ToString();
        load_data_2_m_p_noi_dung_cau();
    }

    protected void cs10_Click(object sender, EventArgs e)
    {
        m_hdf_index.Value = table_index.Rows[9].Cells[0].InnerText;
        load_data_2_lbl_bai();
        m_lbl_stt.Text = table_index.Rows[9].Cells[1].InnerText;
        m_hdf_index_items.Value = table_index.Rows[9].Cells[2].InnerText;
        US_DM_CAU v_us_dm_cau = new US_DM_CAU();
        DS_DM_CAU v_ds_dm_cau = new DS_DM_CAU();
        v_us_dm_cau.FillDatasetBySTT(v_ds_dm_cau, CIPConvert.ToDecimal(m_lbl_stt.Text), CIPConvert.ToDecimal(m_hdf_id_bai_test.Value));
        DataTable dt = v_ds_dm_cau.Tables["DM_CAU"];
        DataRow dr = dt.Rows[0];
        m_hdf_id_cau.Value = dr["ID"].ToString();
        load_data_2_m_p_noi_dung_cau();
    }
}